<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
    <link rel="stylesheet" href="../static/css/typo.css">
    <link rel="stylesheet" href="../static/lib/prism/prism.css">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
    <link rel="stylesheet" href="../static/css/me.css">
</head>
<body>

    <!-- 导航 -->
    <nav th:replace="_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
        <div class="ui container">
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui teal header item">Blog</h2>
                <a href="#" class="m-item item m-mobel-hide"><i class=" home icon"></i>首页</a>
                <a href="#" class="m-item item m-mobel-hide"><i class=" idea icon"></i>分类</a>
                <a href="#" class="m-item item m-mobel-hide"><i class=" tags icon"></i>标签</a>
                <a href="#" class="m-item item m-mobel-hide"><i class=" clone icon"></i>归档</a>
                <a href="#" class="m-item item m-mobel-hide"><i class=" info icon"></i>关于我</a>
                <div class="right m-item item m-mobel-hide">
                    <div class="ui icon inverted transparent input">
                        <input type="text" placeholder="搜索">
                        <i class="search link icon"></i>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle black icon button m-right-top m-mobel-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>
    
    <!-- 中间内容 -->
    <div id="waypoint" class="m-container-small m-padded-tb-big animated fadeIn">
        <div class="ui container">
            <div class="ui top attached segment">
                <div class="ui horizontal link list">
                    <div class="item">
                        <img src="https://unsplash.it/100/100?image=1005" th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image">
                        <div class="content">
                            <a href="#" target="_blank" th:href="@{/about}" class="header" th:text="${blog.user.nickname}">范占国</a>
                        </div>
                    </div>
                    <div class="item">
                        <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2021-11-5</span>
                    </div>
                    <div class="item">
                        <i class="eye icon"></i>&nbsp;&nbsp;<span th:text="${blog.views}==null ? 0 : ${blog.views}">132</span>
                    </div>
                </div>
            </div>
            <div class="ui attached segment">
                <!-- 图片区域 -->
                <img src="https://unsplash.it/800/450?image=1005" th:src="@{${blog.firstPicture}}" alt="" class="ui fluid rounded image">
            </div>
            <div class="ui attached padded segment">
                <!-- 内容 -->
                <div class="ui right aligned basic segment">
                    <div class="ui orange basic label" th:text="${blog.flag}">原创</div>
                </div>
                <h2 class="ui center aligned header" th:text="${blog.title}">印第安人的诞生</h2>
                <div id="content" class="typo typo-selection js-toc-content m-padded-lr-reponsive m-padded-tb-large" th:utext="${blog.content}">
                    博客内容
                </div>
                <!-- 标签 -->
                <div class="m-padded-lr-reponsive">
                    <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">神话故事</div>
                </div>
                <!-- 赞赏 -->
                <div th:if="${blog.appreciation}">
                    <div class="ui center aligned basic segment">
                        <button id="payButton" class="ui orange basic circular button">赞赏</button>
                    </div>
                    <div class="ui payQR flowing popup transition hidden">
                        <div class="ui orange basic label">
                            <div class="ui images" style="font-size: inherit !important;">
                                <div class="image m-padded-lr-samll">
                                    <img src="../static/images/wechatCollectCode.jpg" th:src="@{/images/wechatCollectCode.jpg}" alt="" class="ui rounded bordered image" style="width: 120px;">
                                </div>
                                <div class="image m-padded-lr-samll">
                                    <img src="../static/images/AlipayPaymentCode.jpg" th:src="@{/images/AlipayPaymentCode.jpg}" alt="" class="ui rounded bordered image" style="width: 120px;">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                        
            </div>
            <div class="ui attached positive message" th:if="${blog.shareStatement}">
                <!-- 博客信息 -->
                <div class="ui middle aligned grid" >
                    <div class="eleven wide column">
                        <ul class="list">
                            <li>作者：<span th:text="${blog.user.nickname}">范占国</span> <a href="#" target="_blank" th:href="@{/about}">（联系作者）</a></li>
                            <li>发表时间： <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2021-11-8 11:19</span> </li>
                            <li>版权声明： 自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                            <li>公众号转载：请在文末添加作者公众号二维码</li>
                        </ul>
                    </div>
                    <div class="five wide column">
                        <img src="../static/images/微信图片_20211105175546.jpg" th:src="@{/images/微信图片_20211105175546.jpg}" alt="" class="ui right floated rounded bordered image" style="width: 110px;">
                    </div>
                </div>
            </div>
            <div class="ui bottom attached segment" th:if="${blog.commentabled}">
                <!-- 留言区域列表 -->
                <div id="comment-container"  class="ui teal segment">
                    <div th:fragment="commentList">
                        <div class="ui threaded comments" style="max-width: 100%">
                            <h3 class="ui dividing header">评论</h3>
                            <div class="comment" th:each="comment : ${comments}">
                                <a class="avatar">
                                    <img src="https://unsplash.it/100/100?image=1005" alt="" th:src="@{${comment.avatar}}">
                                </a>
                                <div class="content">
                                    <a class="author">
                                        <span th:text="${comment.nickname}" >Matt</span>
                                        <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminComment}">博主</div>
                                    </a>
                                    <div class="metadata">
                                        <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                    </div>
                                    <div class="text" th:text="${comment.content}">太赞了！ </div>
                                    <div class="actions">
                                        <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">回复</a>
                                    </div>
                                </div>
                                <div class="comments" th:if="${#arrays.length(comment.replyComment)>0}">
                                    <div class="comment" th:each="reply : ${comment.replyComment}">
                                        <a class="avatar">
                                            <img src="https://unsplash.it/100/100?image=1005" alt="" th:src="@{${reply.avatar}}">
                                        </a>
                                        <div class="content">
                                            <a class="author">
                                                <span th:text="${reply.nickname}">Matt</span>
                                                <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${reply.adminComment}">博主</div>
                                                &nbsp;<span th:text="|@ ${reply.parentComment.nickname}|" class="m-teal">@ 小白</span>
                                            </a>
                                            <div class="metadata">
                                                <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                            </div>
                                            <div class="text" th:text="${reply.content}">太赞了！ </div>
                                            <div class="actions">
                                                <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">回复</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--/*-->
                            <div class="comment">
                                <a class="avatar">
                                    <img src="https://unsplash.it/100/100?image=1005">
                                </a>
                                <div class="content">
                                    <a class="author">Elliot Fu</a>
                                    <div class="metadata">
                                        <span class="date">昨天上午12:30</span>
                                    </div>
                                    <div class="text">
                                        <p>這對我的研究是非常有用.謝謝!</p>
                                    </div>
                                    <div class="actions">
                                        <a class="reply" data-commentid="1" data-commentnickname="fzg" onclick="reply(this)">回复</a>
                                    </div>
                                </div>
                                <div class="comments">
                                    <div class="comment">
                                        <a class="avatar">
                                            <img src="https://unsplash.it/100/100?image=1005">
                                        </a>
                                        <div class="content">
                                            <a class="author">Jenny Hess</a>
                                            <div class="metadata">
                                                <span class="date">刚刚</span>
                                            </div>
                                            <div class="text">艾略特你永远是多么正确 :) </div>
                                            <div class="actions">
                                                <a class="reply">回复</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="comment">
                                <a class="avatar">
                                    <img src="https://unsplash.it/100/100?image=1005">
                                </a>
                                <div class="content">
                                    <a class="author">Joe Henderson</a>
                                    <div class="metadata">
                                        <span class="date">5 天以前</span>
                                    </div>
                                    <div class="text">老兄，这太棒了。非常感谢。 </div>
                                    <div class="actions">
                                        <a class="reply">回复</a>
                                    </div>
                                </div>
                            </div>
                            <!--*/-->
                        </div>
                    </div>

                </div>
                <div id="comment-form" class="ui form">
                    <input type="hidden" name="blog.id" th:value="${blog.id}">
                    <input type="hidden" name="parentComment.id" value="-1">
                    <div class="field">
                        <textarea name="content" placeholder="请输入评论信息..."></textarea>
                    </div>
                    <div class="fields">
                        <div class="field m-mobile-wide m-margin-bottom-samll">
                            <div class="ui left icon input">
                                <i class="user icon"></i>
                                <input type="text" name="nickname" placeholder="姓名" th:value="${session.user}!=null ? ${session.user.nickname}">
                            </div>                           
                        </div> 
                        <div class="field m-mobile-wide m-margin-bottom-samll">
                            <div class="ui left icon input">
                                <i class="mail icon"></i>
                                <input type="email" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                            </div>
                        </div>      
                        <div class="field m-mobile-wide m-margin-bottom-samll ">
                            <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                        </div>               
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="toolbar" class="m-padded m-fixed m-right-bottom" style="display: none;">
        <div class="ui vertical icon buttons">
            <a type="button" class="ui toc teal button">目录</a>
            <a href="#comment-container" class="ui teal button">留言</a>
            <a class="ui weichat button"><i class="weixin icon"></i></a>
            <div id="toTop-button" class="ui icon button"><i class="chevron up icon"></i></div>
        </div>
    </div>

    <div class="ui toc-container flowing popup transition hidden" style="width: 300px;">
        <ol class="js-toc"></ol>
    </div>

    <div id="qrcode" class="ui wechat-qr flowing popup transition hidden">
        <!-- <img src="./images/微信图片_20211105175546.jpg" alt="" style="width: 120px;"> -->
    </div>

    <br>
    <br>
    <!-- 底部Footer -->
    <footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid">
                <div class="three wide column" >
                    <div class="ui inverted link list">
                        <div class="item">
                           <img src="./images/微信图片_20211105115105.jpg" class="ui rounded image" alt="" style="width: 100px;">
                        </div>
                   </div>
                </div>
                <div class="three wide column" >
                    <h4 class="ui inverted header m-text-thin m-textspaced">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">用户故事</a>
                    </div> 
                </div>
                <div class="three wide column" >
                    <h4 class="ui inverted header m-text-thin m-textspaced">联系我们</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email: 1841633803@qq.com</a>
                        <a href="#" class="item">QQ: 1840633803</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-textspaced" >最新博客</h4>
                    <p class="m-text-thin m-textspaced m-opacity-mini">世上无难事，只要肯放弃。</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-thin m-textspaced m-opacity-tiny">Copyright  ©  2021 Blog Designed by fzg</p>
        </div>
    </footer>

    <!--/*/<th:block th:replace="_fragments :: script">/*/-->
        <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.3/jquery.scrollTo.min.js"></script>
        <script src="../static/lib/prism/prism.js"></script>
        <script src="../static/lib/tocbot/tocbot.min.js"></script>
        <script src="../static/lib/qrcode/qrcode.min.js"></script>
        <script src="../static/lib/waypoints/jquery.waypoints.min.js"></script>
    <!--/*/</th:block>/*/-->
    
   <script th:inline="javascript">

        $('.menu.toggle').click(function(){
            $('.m-item').toggleClass('m-mobel-hide');
        });

        $('#payButton').popup({
            popup : $('.payQR.popup'),
            on : 'click',
            position : 'bottom center'
        });
        // 目录初始化
        tocbot.init({
            // Where to render the table of contents.
            tocSelector: '.js-toc',
            // Where to grab the headings to build the table of contents.
            contentSelector: '.js-toc-content',
            // Which headings to grab inside of the contentSelector element.
            headingSelector: 'h1, h2, h3',
            // For headings inside relative or absolute positioned containers within content.
            hasInnerContainers: true,
        });


        $('.toc.button').popup({
            popup : $('.toc-container.popup'),
            on : 'click',
            position : 'left center'
        });

        $('.weichat').popup({
            popup : $('.wechat-qr'),
            position : 'left center'
        });

        // 生成二维码
        var serurl = /*[[#{blog.serurl}]]*/"127.0.0.1:8080";
        var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
        var qrcode = new QRCode("qrcode", {
                text: serurl+url,
                width: 110,
                height: 110,
                colorDark : "#000000",
                colorLight : "#ffffff",
                correctLevel : QRCode.CorrectLevel.H
        });

        // 平滑滚动
        $('#toTop-button').click(function(){
            $(window).scrollTo(0,500);
        });

        // 滚动侦测
        var waypoint = new Waypoint({
            element: document.getElementById('waypoint'),
            handler: function(direction) {
                if(direction == 'down'){
                    $('#toolbar').show(100);
                }else{
                    $('#toolbar').hide(500);
                }
            }
        });

        $('.ui.form').form({
            fields: {
                content: {
                    identifier: 'content',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入评论内容'
                    }]
                },
                nickname: {
                    identifier: 'nickname',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入您的名字'
                    }]
                },
                email: {
                    identifier: 'email',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入邮箱地址'
                    }]
                },
            }
        });

        $(function (){
            $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"comments/18");
        });

        $('#commentpost-btn').click(function (){
            var boo = $('.ui.form').form('validate form');
            if (boo){
                console.log("校验成功！");
                postData();
            }else {
                console.log("校验失败！");
            }
        })

        function postData(){
            $("#comment-container").load(/*[[@{/comments}]]*/"",{
                "parentComment.id" : $("[name='parentComment.id']").val(),
                "blog.id" : $("[name='blog.id']").val(),
                "nickname" : $("[name='nickname']").val(),
                "email" : $("[name='email']").val(),
                "content" : $("[name='content']").val(),
            },function (responseTxt,statusTxt,xhr){
                // $(window).scrollTo($('#comment-container'),500);
                clearContent();
            });
        }
        function clearContent(){
            $("[name='content']").val('');
            $("[name='parentComment.id']").val(-1);
            $("[name='content']").attr("placeholder","请输入评论信息...");
        }
        function reply(obj){
            var commentId = $(obj).data('commentid');
            var commentNickname = $(obj).data('commentnickname');
            $("[name='content']").attr("placeholder","@"+commentNickname).focus();
            $("[name='parentComment.id']").val(commentId);
            $(window).scrollTo($('comment-form'),500);
        }

    </script>
</body>
</html>